{include file="public_head"}
{include file="public_menu"}
  <div class="content_center">
    <div class="main_center">
      {include file="public_information_menu"}
      <div class="main_right right">
        <div class="main_right_title">收货地址</div>
        <div class="address_con">
          <div class="add_button">
            <input type="button" value="新增收货地址" onclick="add_address()">
          </div>
          {volist name="data" id="item"}
          <div class="my_address">
            <!--<div class="title">收货地址{$key+1}</div>-->
            <table border="0" class="table_assress">
              <tr>
                <td class="basic text-right">收货人：</td>
                <td class="det">{$item.name}</td>
              </tr>
              <tr>
                <td class="basic text-right">所在地区：</td>
                <td class="det">{$item.area_info}</td>
              </tr>
              <tr>
                <td class="basic text-right">地址：</td>
                <td class="det">{$item.address}</td>
              </tr>
              <tr>
                <td class="basic text-right">手机：</td>
                <td class="det">{$item.phone}</td>
              </tr>
            </table>
            <button type="button" class="close" aria-label="close"><span aria-hidden="true" onclick="delete_address({$item.id})">&times;</span></button>
            <div class="operate">
              {eq name="$item.status" value="1"}
              <a href="#" style="cursor:default">默认地址</a>
              {else/}
              <a href="javascript:default_address({$item.id});">设为默认地址</a>
              {/eq}
              <a href="javascript:edit_address({$item.id});">编辑</a>
            </div>
          </div>
          {/volist}
        </div>
      </div>
    </div>
  </div>
<script>
  // 默认地址
  function default_address(aid) {

    $.ajax({
      url: "{:url('shop/Member/default_address')}",
      type: 'post',
      dataType: 'json',
      data:{'id':aid},
      success: function (t) {
        if (t.code==200) {
          layer.msg('设置默认地址成功');
          window.location.href = "{:url('shop/address/index')}";
        }else {
          layer.msg('网络繁忙稍后再试', {icon: 2});
        }
      }
    });
  }

  // 添加地址ifame层
  function edit_address(id) {
    layer.open({
      title: '收货地址',
      type: 2,
      area: ['700px', '530px'],
      fixed: false, //不固定
      maxmin: true,
      content: "{:url('shop/address/edit_address')}?id="+id
    });

  }


  // 添加地址
  function add_address() {
    layer.open({
      title: '收货地址',
      type: 2,
      area: ['700px', '530px'],
      fixed: false, //不固定
      maxmin: true,
      content: "{:url('shop/address/account_address')}"
    });

  }

  // 删除收货地址
  function delete_address(aid) {
    layer.confirm('确认删除地址吗？', {
      btn: ['确定', '否'] //按钮
    }, function () {
      $.post("{:url('shop/Member/delete_address')}", {'aid': aid}, function (t) {
        if (t.code = 200) {
          layer.msg('删除成功', {icon: 1});
          setTimeout(function(){
            layer.closeAll('loading');
            // 跳转页面
            window.location.href = "{:url('shop/address/index')}";
          }, 3000);
        } else {
          layer.msg('网络繁忙稍后再试', {icon: 2});
        }
      });
    });

  }
</script>
{include file="public_foot"}
